package offer;

import java.util.LinkedList;
import java.util.Stack;

public class ReversePrint {
    public static void main(String[] args) {
        reversePrint1(null);
    }

    /**
     * 递归的方式从尾部到头部打印链表
     *
     * @param head
     */
    public void print(ListNode head) {
        if (head == null) return;
        print(head.next);
        System.out.println(head.val);
    }

    public static void reverse(int[] res, ListNode head, int len) {
        res = new int[12];
    }

    public static int[] reversePrint1(ListNode head) {
        if (head == null) {
            return new int[0];
        }
        int len = 0;
        ListNode curr = head;
        Stack<Integer> stack = new Stack<>();
        while (curr != null) {
            stack.add(curr.val);
            len++;
            curr = curr.next;
        }
        int[] res = new int[len];
        int i = 0;
        while (stack.size() > 0) {
            res[i] = stack.pop();
            i++;
        }
        return res;

    }


    public class ListNode {
        int val;
        ListNode next;

        ListNode(int x) {
            val = x;
        }
    }
}
